package myplaydog.qf.com.yimixianproject.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import org.xutils.view.annotation.ViewInject;
import org.xutils.x;

import myplaydog.qf.com.yimixianproject.R;
import myplaydog.qf.com.yimixianproject.bean.KindContentEnitiy;
import myplaydog.qf.com.yimixianproject.url.AppNetConfig;

/**
 * Created by guqiang on 2016/9/28.
 * User: guqiang
 * Date: 2016/9/28
 * Email:xxxx@163.com
 * Project: YiMiXianProject
 */
public class KindContentAdapter extends MyBaseAdapter<KindContentEnitiy.GoodsBean> {

    public KindContentAdapter(Context context) {
        super(context);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        ViewHolder viewHolder =null;
        if (convertView ==null){

            convertView =getInflater().inflate(R.layout.item_kind_content,parent,false);
            viewHolder =new ViewHolder(convertView);
            convertView.setTag(viewHolder);
        }else {
            viewHolder = (ViewHolder) convertView.getTag();
        }

        KindContentEnitiy.GoodsBean item =getItem(position);
        Log.e("--11--11--",item.getName());
        if (item.getName()!=null){
            viewHolder.name.setText(item.getName());
        }
        if (TextUtils.isEmpty(item.getSub_name())){
            viewHolder.subName.setVisibility(View.INVISIBLE);
        }else {
            viewHolder.subName.setText(item.getSub_name());
        }

        if (!TextUtils.isEmpty(item.getUnit_desc())){
            viewHolder.unitDesc.setText(item.getUnit_desc());
        }
        if (!TextUtils.isEmpty(item.getUnit_price())){
            viewHolder.price.setText("￥"+item.getUnit_price());
        }
        if (!TextUtils.isEmpty(item.getUnit_old_price())){
            viewHolder.oldPrice.setText("￥"+item.getUnit_old_price());
        }else {
            viewHolder.oldPrice.setVisibility(View.GONE);
        }

        if (!TextUtils.isEmpty(item.getImg())){
            x.image().bind(viewHolder.imag,String.format(AppNetConfig.URL_KID_ICON,item.getImg()));
        }
        if (!TextUtils.isEmpty(item.getPromotion_img())){
            viewHolder.promotion.setVisibility(View.VISIBLE);
            x.image().bind(viewHolder.promotion,String.format(AppNetConfig.URL_KID_ICON,item.getPromotion_img()));
        }else {
            viewHolder.promotion.setVisibility(View.GONE);
        }
        return convertView;
    }


    public class ViewHolder{

        //文本
        @ViewInject(R.id.item_kind_content_name)
        private TextView name;
        @ViewInject(R.id.item_kind_content_sub_name)
        private TextView subName;
        @ViewInject(R.id.item_kind_content_unit_desc)
        private TextView unitDesc;
        @ViewInject(R.id.item_kind_content_price)
        private TextView price;
        @ViewInject(R.id.item_kind_content_old_price)
        private TextView oldPrice;
        @ViewInject(R.id.item_kind_content_position)
        private TextView positionTv;

        //图片
        @ViewInject(R.id.item_kind_content_munus)
        private ImageView munus;
        @ViewInject(R.id.item_kind_content_pius)
        private ImageView pius;
        @ViewInject(R.id.item_kind_content_card)
        private ImageView card;
        @ViewInject(R.id.item_kind_content_img)
        private ImageView imag;
        @ViewInject(R.id.item_kind_content_promotion_img)
        private ImageView promotion;
        public ViewHolder(View view){
            x.view().inject(this,view);
        }
    }

//    public class ViewHolder{
//
//        @ViewInject(R.id.item_kind_navigation_name)
//        private TextView name;
//        @ViewInject(R.id.item_kind_navigation_sub_name)
//        private TextView subName;
//        public ViewHolder(View v){
//            x.view().inject(this,v);
//        }
//    }
}
